Please note that JavaScript is currently only available in Netscape Navigator 2.0 and Explorer 3.01 or higher. Do not assume that all in your audience are using a JavaScript enabled browser.
Inside the script tag enclosing the script you can specify which version of JavaScript that is required for the commands to work. When the page is loaded, older browser which don't handle JavaScript 1.1 or 1.2 will ignore the statements inside these sections:
<SCRIPT LANGUAGE="JavaScript"> | This code will always be performed if JavaScript is available. |
<SCRIPT LANGUAGE="JavaScript1.1"> | The code inside this script tag will only be performed in Navigator 3.0, Explorer 3.01 and later versions. |
<SCRIPT LANGUAGE="JavaScript1.2"> | The code inside this script tag will only be performed in Navigator 4.0, Explorer 4.0 and later versions. |
The following code section:
<SCRIPT LANGUAGE="JavaScript"> <!-- Beginning of JavaScript - var theText = ""; var jsVersion = "1.0" theText = "JavaScript Version 1.0 is always available"; // - End of JavaScript - --> </SCRIPT> <SCRIPT LANGUAGE="JavaScript1.1"> <!-- Beginning of JavaScript - jsVersion = "1.1" theText = theText + "<BR>This line is displayed in a browser that supports JavaScript Version 1.1"; // - End of JavaScript - --> </SCRIPT> <SCRIPT LANGUAGE="JavaScript1.2"> <!-- Beginning of JavaScript - jsVersion = "1.2" theText = theText + "<BR>This line is displayed in a browser which supports JavaScript Version 1.2"; // - End of JavaScript - --> </SCRIPT>
will produce the following result in your browser:
How to use
If you have code that only works in Navigator 3 or 4, you should place the code inside the JavaScript1.1 or the JavaScript1.2 script tag. This enables you to use new JavaScript statements without getting syntax errors in older browsers.To know which version of JavaScript that is available, in e.g. event handlers, you can check the value of the variable jsVersion if you use the JavaScript sections in this example as a template for your JavaScript-enhanced pages:
Simple example:
if (jsVersion == "1.0") { document.bgColor = "#EEEEEE"; }